<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"
	import="beans.UserBean,beans.MyEventBean,beans.EventBean,java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">

<title>MyEvents - <%
	UserBean currentUser = (UserBean) session
			.getAttribute("currentSessionUser");
	out.print(currentUser.getName());
%></title>

<title>MyEvents - </title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<!-- Le styles -->
<link href="css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
	padding-top: 60px;
	padding-bottom: 40px;
}

#sexyline {
	margin: 25px 0;
	height: 1px;
	background: #eeeee;
	background: -webkit-gradient(linear, 0 0, 100% 0, from(white), to(white),
		color-stop(50%, grey) );
}
​#glowing {
      border: 0px solid #D11919;
    border-radius: 6px; 
    padding: 4px 4px 4px 4px;    
     
    -moz-animation-name: glow;
    -moz-animation-timing-function: ease-in;
    -moz-animation-iteration-count: infinite;
    -moz-animation-direction: alternate;
    -moz-animation-duration: 500ms;
	}
	@-moz-keyframes glow {
    0% { box-shadow: 0 0 5px #D11919; }
    100% { box-shadow: 0 0 20px #D11919; }
	}
	<% if (currentUser.getAdmin())
		out.print(".navbar-inner { background: #a90329; background: -moz-linear-gradient(top,  #a90329 0%, #8f0222 44%, #6d0019 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a90329), color-stop(44%,#8f0222), color-stop(100%,#6d0019)); background: -webkit-linear-gradient(top,  #a90329 0%,#8f0222 44%,#6d0019 100%); background: linear-gradient(to bottom,  #a90329 0%,#8f0222 44%,#6d0019 100%);}");
		out.print(" .navbar .brand { color: white; }"); %>  
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet">

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<!--Custom JS scripts-->

<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144"
	href="ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114"
	href="ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72"
	href="ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed"
	href="ico/apple-touch-icon-57-precomposed.png">
</head>

<body>

	<div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="http://localhost:8080/dropin/LoginServlet">drop.in</a>
          <div class="nav-collapse">
            <ul class="nav pull-left">
              <li class="active pull-left"><a href="http://localhost:8080/dropin/LoginServlet">Home</a></li>
              <li class="pull-left"><a href="http://localhost:8080/dropin/eventcreation.jsp">Create a new event</a></li>
              <li class="dropdown" id="searchmenu"><a class="dropdown-toggle" data-toggle="dropdown" href="#searchmenu">Search<b class="caret"></b></a>
              <ul class="dropdown-menu">
              <li><a href="http://localhost:8080/dropin/searchuser.jsp">Search Users</a></li>
              <li><a href="http://localhost:8080/dropin/searchevent.jsp">Search Events</a></li>
              </ul>
              </li>
              </ul><ul class="nav pull-right">
              <li class="dropdown pull-right" id="notifications">
              <% ArrayList<EventBean> events = (ArrayList<EventBean>)session.getAttribute("usersevent");
    			int j = 0;
    			for (int i = 0; i < events.size(); i++) {
    				if (events.get(i).isNotification())
    				j++;
    			} %>
    			<a class="dropdown-toggle" data-toggle="dropdown" href="#notifications"> <span <% if (j>0) out.print("id='glowing'"); %>> Notifications (<% out.print(j); %>)</span><b class="caret"></b> </a>
   			<ul class="dropdown-menu">
      		<li style="padding-left: 5px;">Please rate your host/guest(s) for these events:</li>
         			<li class="divider"></li>
      
      			<% for (int i = 0; i < events.size(); i++) {
      			   		if (events.get(i).isNotification()) {
      			   			String startt = events.get(i).getStartTimeStamp().toString();
      			   		startt = startt.substring(0, 19);
            			startt = startt.replace("-", "");
            			startt = startt.replace(":", "");
            			startt = startt.replace(" ", "");
      			   			out.print("<li><a href='http://localhost:8080/dropin/EventServlet?host=" + events.get(i).getHost() + "&start=" + startt + "'>" + events.get(i).getName() + "</a></li>");
      			   		}
      			} %>
    </ul>
  </li>
  <li class="pull-right"><a href="http://localhost:8080/dropin/LogoutServlet">Log Out</a></li>
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

	<div class="container">

		
		<div class="hero-unit" style="padding: 10px 10px 10px 10px;">
			<div style="text-align: center;">
				<h2>My Events</h2>
			</div>
		</div>
		
			

		<!-- This div class objective is to assign the values of the box... -->
	
		<div class="row">
			<div class="span12">
				<ul class="nav nav-tabs">
					<%
					// not complete, atm only for test purposes, we need to assign the "pestanas" to Gupcoming and Gpast
						String currentboxx = (String) session.getAttribute("currentbox");
						    if (currentboxx.equals("Gupcoming")) {  
							out.print("<li class='active'><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Gupcoming&page=1'>Gupcoming</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Gpast&page=1'>Gpast</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Hupcoming&page=1'>Hupcoming</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Hpast&page=1'>Hpast</a></li>");
					       } else if (currentboxx.equals("Gpast")){
					    	   out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box=Gupcoming&page=1'>Gupcoming</a></li>");
								out.print("<li class='active'><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box=Gpast&page=1'>Gpast</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box=Hupcoming&page=1'>Hupcoming</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box=Hpast&page=1'>Hpast</a></li>");
						}  else if (currentboxx.equals("Hupcoming")) {
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Gupcoming&page=1'>Gupcoming</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Gpast&page=1'>Gpast</a></li>");
							out.print("<li class='active'><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Hupcoming&page=1'>Hupcoming</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Hpast&page=1'>Hpast</a></li>");
						} else { // Hpast
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Gupcoming&page=1'>Gupcoming</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Gpast&page=1'>Gpast</a></li>");
							out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Hupcoming&page=1'>Hupcoming</a></li>");
							out.print("<li class='active'><a href='http://localhost:8080/dropin/MyEventServlet?id="
									+ currentUser.getEmail()
									+ "&box=Hpast&page=1'>Hpast</a></li>");
						}
					%>
				</ul>
				<%
				    //start printing useful data
					Integer pg = (Integer) session.getAttribute("currentpagenumber");
					ArrayList<MyEventBean> myevent = (ArrayList<MyEventBean>) session
							.getAttribute("displayevents");
					if ((myevent.isEmpty()) || ((pg - 1) * 10 >= myevent.size())) {
						out.print("<blockquote style='text-align: center; height: 100px; font-size: 18px; font-style: italic; padding-top: 70px;'>No events... Forever alone!</blockquote>");
					} else {
						
					/* 	<table border="1">
						<tr>
						<th>Header 1</th>
						<th>Header 2</th>
						</tr>
						<tr>
						<td>row 1, cell 1</td>
						<td>row 1, cell 2</td>
						</tr>
						<tr>
						<td>row 2, cell 1</td>
						<td>row 2, cell 2</td>
						</tr>
						</table> */						
						
						 if (currentboxx.equals("Hpast")) {
						       
							 %>
								<table class="table table-hover">
								<tr>
								<th>Event Name</th>
								<th>Start Time</th>
								<th>Available Guest Spots</th>
								<th># Participants</th>
								<th>Event Rating</th>
								</tr>
								
								<% 
							for (int i = (pg - 1) * 10; i < (pg * 10); i++) {
								if (i < myevent.size()) { 
									String startt = myevent.get(i).getStamp().toString();
			      			   		startt = startt.substring(0, 19);
			            			startt = startt.replace("-", "");
			            			startt = startt.replace(":", "");
			            			startt = startt.replace(" ", "");
			            			
								%>
								<tr>
								<td><%out.print("<a href='http://localhost:8080/dropin/EventServlet?host=" + currentUser.getEmail() + "&start=" + startt + "'>" + myevent.get(i).getEventname() + "</a>");%></td>
								<td><% out.print(myevent.get(i).getStamp());%></td>
								<td><%out.print(myevent.get(i).getnGuestspots());%></td>
								<td><%out.print(myevent.get(i).getnParticipants());%></td>
								<td><%out.print(myevent.get(i).getRating());%></td>
								</tr>
								<% 	
									
								
								}
							}
								
								%>
								</table>
								<%
							//assuming the box=sent (do nothing until the firts part of the if is ready)
						} 
						 
						 else {
							if (currentboxx.equals("Hupcoming")) {
								%>
								<table class="table table-hover">
								<tr>
								<th>Event Name  </th>
								<th>Start Time  </th>
								<th>Available Guest Spots  </th>
								<th># Participants  </th>
								</tr>
								
								
								<%
								for (int i = (pg - 1) * 10; i < (pg * 10); i++) {
									if (i < myevent.size()) { 
										String startt = myevent.get(i).getStamp().toString();
				      			   		startt = startt.substring(0, 19);
				            			startt = startt.replace("-", "");
				            			startt = startt.replace(":", "");
				            			startt = startt.replace(" ", "");
				            			
									%>
									<tr>
									<td><%out.print("<a href='http://localhost:8080/dropin/EventServlet?host=" + currentUser.getEmail() + "&start=" + startt + "'>" + myevent.get(i).getEventname() + "</a>");%></td>
									<td><% out.print(myevent.get(i).getStamp());%></td>
									<td><%out.print(myevent.get(i).getnGuestspots());%></td>
									<td><%out.print(myevent.get(i).getnParticipants());%></td>
									</tr>
									<% 	
										
									
									}
								}
									
									%>
									</table>
									<%
							}
						
						
						else {
							if  (currentboxx.equals("Gupcoming")) {
								%>
								<table class="table table-hover">
								<tr>
								<th>Event Name</th>
								<th>Start Time</th>
								<th>Available Guest Spots</th>
								<th># Participants</th>
								<th>Host</th>
								<th>Avg.Host Rating</th>
								</tr>
								
								
								<%
								for (int i = (pg - 1) * 10; i < (pg * 10); i++) {
									if (i < myevent.size()) { 
										String startt = myevent.get(i).getStamp().toString();
				      			   		startt = startt.substring(0, 19);
				            			startt = startt.replace("-", "");
				            			startt = startt.replace(":", "");
				            			startt = startt.replace(" ", "");
				            			
									%>
									<tr>
									<td><%out.print("<a href='http://localhost:8080/dropin/EventServlet?host=" + myevent.get(i).getHost() + "&start=" + startt + "'>" + myevent.get(i).getEventname() + "</a>");%></td>
									<td><% out.print(myevent.get(i).getStamp());%></td>
									<td><%out.print(myevent.get(i).getnGuestspots());%></td>
									<td><%out.print(myevent.get(i).getnParticipants());%></td>
									<td><%out.print("<a href='http://localhost:8080/dropin/VisitServlet?visitid="+ myevent.get(i).getHost() + "'>" + myevent.get(i).gethostName() + "</a>");%></td>
									<td><%out.print(myevent.get(i).gethostavgRating());%></td>
									</tr>
									<% 	
							
									
									}
								}
									
									%>
									</table>
									<%
							}
							else { //We are at Gpast
								%>
								<table class="table table-hover">
								<tr>
								<th>Event Name</th>
								<th>Start Time</th>
								<th>Available Guest Spots</th>
								<th># Participants</th>
								<th>Host</th>
								<th>Avg.Host Rating</th>
								<th>My Rating</th>
								</tr>
								
								
								<%
								for (int i = (pg - 1) * 10; i < (pg * 10); i++) {
									if (i < myevent.size()) { 
										String startt = myevent.get(i).getStamp().toString();
				      			   		startt = startt.substring(0, 19);
				            			startt = startt.replace("-", "");
				            			startt = startt.replace(":", "");
				            			startt = startt.replace(" ", "");
				            			
									%>
									<tr>
									<td><%out.print("<a href='http://localhost:8080/dropin/EventServlet?host=" + myevent.get(i).getHost() + "&start=" + startt + "'>" + myevent.get(i).getEventname() + "</a>");%></td>
									<td><% out.print(myevent.get(i).getStamp());%></td>
									<td><%out.print(myevent.get(i).getnGuestspots());%></td>
									<td><%out.print(myevent.get(i).getnParticipants());%></td>
									<td><%out.print("<a href='http://localhost:8080/dropin/VisitServlet?visitid="+ myevent.get(i).getHost() + "'>" + myevent.get(i).gethostName() + "</a>");%></td>
									<td><%out.print(myevent.get(i).gethostavgRating());%></td>
									<td><%out.print(myevent.get(i).getRating());%></td>
									</tr>
									<% 	
							
									
									}
								}
									
									%>
									</table>
									<%
							}
						}
					}
					}
				%>

				<div class="pagination" align="center">
					<ul>
						<%
							//Integer pg = (Integer)session.getAttribute("currentpagenumber");
							if (pg == 1) {
								out.print("<li class='disabled'><a href='http://localhost:8080/dropin/myevent.jsp' class='disabled'>Prev</a></li>");
							} else {
								out.print("<li><a href='http://localhost:8080/dropin/MyeventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg - 1) + "'>Prev</a></li>");
							}
						%>
						<%
							if (pg == 1) {
								out.print("<li class='active'><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page=1'>1</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page=2'>2</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page=3'>3</a></li>");
							} else {
								out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg - 1)
										+ "'>"
										+ Integer.toString(pg - 1) + "</a></li>");
								out.print("<li class='active'><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg)
										+ "' class='active'>"
										+ Integer.toString(pg) + "</a></li>");
								out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg + 1)
										+ "'>"
										+ Integer.toString(pg + 1) + "</a></li>");
							}
						%>
						<%
							//Integer pg = (Integer)session.getAttribute("currentpagenumber");
							if (pg >= (myevent.size() / 10) + 1) {
								out.print("<li class='disabled'><a href='http://localhost:8080/dropin/myevent.jsp' class='disabled'>Next</a></li>");
							} else {
								out.print("<li><a href='http://localhost:8080/dropin/MyEventServlet?id="
										+ currentUser.getEmail()
										+ "&box="
										+ session.getAttribute("currentbox")
										+ "&page="
										+ Integer.toString(pg + 1) + "'>Next</a></li>");
							}
						%>
					</ul>
				</div>
			</div>
			</div>
			</div>
			<footer>
        		<p style="text-align: center; margin-top: 50px; color: grey;">&copy; PiP 2012</p>
			</footer>

		</div>
		<!-- /container -->

		<!-- Le javascript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->
		<script
			src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
		<script src="js/bootstrap.js"></script>
		<script src="js/bootstrap-alert.js"></script>
		<script src="js/bootstrap-modal.js"></script>
		<script src="js/bootstrap-dropdown.js"></script>
		<script src="js/bootstrap-scrollspy.js"></script>
		<script src="js/bootstrap-tab.js"></script>
		<script src="js/bootstrap-tooltip.js"></script>
		<script src="js/bootstrap-popover.js"></script>
		<script src="js/bootstrap-button.js"></script>
		<script src="js/bootstrap-collapse.js"></script>
		<script src="js/bootstrap-carousel.js"></script>
		<script src="js/bootstrap-typeahead.js"></script>
</body>
</html>
</html>